# coding=utf8
#


"""
分页相关的方法
"""

import math

MIN_PAGE = 1
MAX_PER_PAGE = 20
MIN_PER_PAGE = 1


def get_page_info(request, **kwargs):
    """ 获取分页相关的信息 """

    msg = ""
    ORDERED_COLUMNS = {"create_time",
                       "like_count",
                       "view_count",
                       "modified_on"}

    page = int(kwargs.get("page", "1"))
    per_page = int(kwargs.get("per_page", "100"))
    order_by = kwargs.get("order_by", "create_time")
    reverse = kwargs.get("reverse", False)

    if order_by not in ORDERED_COLUMNS:
        msg = u"排序字段不在允许范围内"

    return (page, per_page, order_by, reverse), msg


def pop_page_info(kwargs):
    """ 将分页相关信息从query dict中剔除 """

    kwargs.pop("per_page", "")
    kwargs.pop("page", "")
    kwargs.pop("order_by", "")
    kwargs.pop("reverse", "")
